import random

import requests
import logging
import config


class ParameterAPI:


    #添加参数
    @classmethod
    def add_dict_data(cls,token,body):
        url=config.monitor_domain+"/system/dict/data"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid, "content-type": "application/json"}
        resp = requests.post(url=url,headers=headers,json=body)
        logging.info(f"add_dict_data url:{url}")
        logging.info(f"add_dict_data resp: {resp.text}")
        return resp

        pass
    #获取参数列表
    @classmethod
    def query_paramDict_list(cls,token,dictLabel,param_manage):
        url = config.monitor_domain + f"/system/dict/data/list?pageNum=1&pageSize=100&dictLabel={dictLabel}&dictType={param_manage}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"query_paramDict_list url:{url}")
        logging.info(f"query_paramDict_list resp: {resp.text}")
        return resp

    # 删除字典参数
    @classmethod
    def delete_dict_param(cls, token, dict_code):
        url = config.monitor_domain + f"/system/dict/data/{dict_code}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.delete(url=url, headers=headers)
        logging.info(f"delete_dict_param url:{url}")
        logging.info(f"delete_dict_param resp: {resp.text}")
        return resp

    #添加监控参数
    @classmethod
    def add_update_monitor_param(cls,token,body):
        url = config.monitor_domain + "/monitor/param/addOrUpdateMonitorParam"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999999))
        headers = {"Authorization": token, "Uuidstr": uuid, "content-type": "application/json"}
        resp = requests.post(url=url, headers=headers, json=body)
        logging.info(f"add_update_monitor_param url:{url}")
        logging.info(f"add_update_monitor_param body:{body}")
        logging.info(f"add_update_monitor_param resp: {resp.text}")
        return resp

    #获取监控参数类型的列表
    @classmethod
    def query_monitor_list(cls, token, paramName):
        url = config.monitor_domain + f"/monitor/param/pageList?paramName={paramName}&pageNum=1&pageSize=100"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"query_monitor_list url:{url}")
        logging.info(f"query_monitor_list resp: {resp.text}")
        return resp

    # 批量删除监控参数
    @classmethod
    def delete_CmMonitorParamByIds(cls, token, ids):
        url = config.monitor_domain + "/monitor/param/deleteCmMonitorParamByIds"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid,"content-type":"application/json"}
        resp = requests.delete(url=url, headers=headers,json=ids)
        logging.info(f"delete_CmMonitorParamByIds url:{url}")
        logging.info(f"delete_CmMonitorParamByIds resp: {resp.text}")
        return resp

    #删除监控参数
    @classmethod
    def delete_monitor_param(cls,token,id):
        url = config.monitor_domain + f"/monitor/param/deleteCmMonitorParamById/{id}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.delete(url=url, headers=headers)
        logging.info(f"delete_monitor_param url:{url}")
        logging.info(f"delete_monitor_param resp: {resp.text}")
        return resp



    pass
